package com.awspaas.user.apps.processforsap.event;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;

import java.util.List;

/**
 * 2025-01-16 赵启棠 SR-2024-12-12-0005 客户商务相关协议评审根据对方主体栏位带出是否关联方交易结果
 */

public class FormSaveAfterByXSHT extends ExecuteListener {
    @Override
    public void execute(ProcessExecutionContext processExecutionContext) throws Exception {
        String bindId = processExecutionContext.getProcessInstance().getId();
        BO mainBo = processExecutionContext.getBO("BO_EU_SAPSD_KHSWXGXYPS");
        String field0006= mainBo.getString("FIELD0006");
        String htlx = "设备consign/租赁协议、加工协议、产能预定协议、合作协议、其他协议";
        List<BO> swList = SDK.getBOAPI().query("BO_EU_SAP_SWLIST").bindId(bindId).list();
        for (BO bo : swList) {
            String companyName = bo.getString("CUSTNAME");//客户名称（全称）
            String sql = "SELECT COUNT(*) FROM BO_EU_GLFQD WHERE RELATE_NAME = ?";
            int count = DBSql.getInt(sql, new Object[]{companyName});
            if (count == 0) {
                bo.set("WHETHER_RELATE", "否");
            } else {
                bo.set("WHETHER_RELATE", "是");
            }
            SDK.getBOAPI().update("BO_EU_SAP_SWLIST", bo);

            //
            String yxqyzt = bo.getString("YXQYZT");
            String whetherRelate = bo.getString("WHETHER_RELATE");
            if (yxqyzt.contains("FH00")&&htlx.contains(field0006)&&whetherRelate.equals("是")){
                SDK.getProcessAPI().setVariable(bindId,"ISZQ","true");
            }
        }
    }
}